function Animator(duration, progress) {
	this.duration = duration;
	this.progress = progress;
	this.next = true;
}
Animator.prototype = {
	constructor: Animator,
	start: function(finished) {
		var startTime = new Date().getTime();
        var duration = this.duration, self = this, timeOut = 0;            
        var vendors = ["webkit", "moz"];
        for(var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i){
        	window.requestAnimationFrame = window[vendors[i] + "RequestAnimationFrame"];
        }
        if (!window.requestAnimationFrame) {
           window.requestAnimationFrame = function (callback, element) {
				var start = 0, finish = 0;
				window.setTimeout(function () {
					start = +new Date();
					callback(start);
					finish = +new Date();
					timeOut = 1000 / 300 - (finish - start);
				}, timeOut);
           };
        }
      	window.requestAnimationFrame(function step(){
	        var p = (new Date().getTime() - startTime) / duration;
	        //var y = p * p * p;
	        self.progress(p, p);
	        if(p >= 1.0){
	        	self.progress(1.0, 1.0);
	          	self.next = false;
	          	finished();
	        }	        
	        if(self.next) window.requestAnimationFrame(step);
    	});
	},
	stop: function() {
		this.next = false;
	}
}

var code = Epg.getParam("code", "ggly_iptv_animation");
CONFIG.COLUMN_CODE = code;
var uri = "column/secondPage/secondPage" + CONFIG.EXT + "?1=1&code="+code;

var SecondPage = {
	userid: Epg.cookie.get("userid"),
	role: Epg.cookie.get("role"),
	orderType: Epg.cookie.get("orderType"),
	side_idx: Epg.getParamInt("side_idx", "0"),							// 侧边栏菜单项隐藏了多少个
	sidePrevButtonId: Epg.getParam("sidePrevButtonId", "side_0"),		// 侧边栏离开时的id
	navPrevButtonId: Epg.getParam("navPrevButtonId", ""),				// 菜单离开时的id
	recommendPrevButtonId: Epg.getParam("recommendPrevButtonId", ""),	// 推荐位离开时的id
	carousel_index: Epg.getParamInt("carousel_index", 1),				// 大推荐位滚屏到第几屏了
	
	sideClick: function() {												// 侧边栏点击事件
		if(SecondPage.sidePrevButtonId === Epg.btn.current.id) return;
		SecondPage.sidePrevButtonId = Epg.btn.current.id;
		//SecondPage.updateSideBg();										// 更新侧边栏菜单项背景图
		SecondPage.init();												// 初始化推荐位信息
	},
	sideBeforeMove: function(dir, current) {							// 侧边栏移动前判断事件
		if("right" === dir) {
			//SecondPage.sidePrevButtonId = current.id;
			if(SecondPage.recommendPrevButtonId !== "") {
				Epg.btn.set(SecondPage.recommendPrevButtonId);
			}else if(Epg.btn.get("label_recommend_0")) {
				Epg.btn.set("label_recommend_0");
			}else {
				Epg.btn.set("recommend_big");	
			}			
			return false;
		}else if("up" === dir && !(current.up && current.up.length > 0)) {
			Epg.btn.set(SecondPage.navPrevButtonId || 'nav_'+navs2[code][0]);
			return false;
		}
	},
	sideFocusHandler: function(current) {								// 侧边栏菜单项获得焦点
		var index = current.index;
		if(index < SecondPage.side_idx) {
			SecondPage.side_idx = SecondPage.side_idx - (SecondPage.side_idx - index);
			G("sides").scrollTop = 46 * SecondPage.side_idx;			// 向上移动46个像素
		}else if(index > (SecondPage.side_idx + (3+navs2[code][1]*2))) {
			SecondPage.side_idx = SecondPage.side_idx + (index - SecondPage.side_idx - (3+navs2[code][1]*2));
			G("sides").scrollTop = 46 * SecondPage.side_idx;			// 向下移动46个像素
		}
		G("side_more").style.visibility = (SecondPage.side_idx + 3 + navs2[code][1]*2) < groups[1].metadatas.length ? 'visible' : 'hidden';
	},
	updateSideBg: function() {											// 更新侧边栏菜单项背景颜色
		var side = parseInt((SecondPage.sidePrevButtonId).slice(5));
		var span = document.querySelector("#sides").getElementsByTagName("span");
		Array.prototype.slice.call(span).forEach(function(value, index) {
			if(index === side) {
				Epg.addClass(value, "side_focus");
				value.getElementsByTagName("div")[0].style.color = "#944600";
				value.getElementsByTagName("div")[0].style.fontWeight = "900";
			}else {
				Epg.removeClass(value, "side_focus");
				value.getElementsByTagName("div")[0].style.color = "#FFFFFF";
				value.getElementsByTagName("div")[0].style.fontWeight = "400";
			}
		});
		G("recommend_down").style.visibility = side === groups[1].metadatas.length ? "hidden" : "visible";
	},
	initSide: function(flag, f) {										// 初始化侧边栏
		var val = code.slice(10);							// 截取二级页面关键字作为侧边栏菜单项背景取色
		SecondPage.initButtons();							// 初始化buttons数组
		var metadatas = groups[1].metadatas;				// 获取配置内容第二个数组
		var html = '<div class="sides">';
		var str = [];										// 把侧边栏菜单项值组装在一起，查询点播前5位的视频信息
		html += '<span class="'+val+'"><div id="side_0" class="side_txt">精选推荐</div></span>';		
		for(var i = 0, length = metadatas.length; i < length; i++) {
			str.push("'"+metadatas[i].value+"'");
			html += '<span class="'+val+'"><div id="side_'+(i+1)+'" class="side_txt">'+metadatas[i].label+'</div></span>';
		}
		if("true" === flag) {
			SecondPage.initDjdak(str.join(","), f);			
		}
		html += '</div>';		
		G("sides").innerHTML = html;
		G("sides").scrollTop = 46 * SecondPage.side_idx;
		G("side_more").style.visibility = (SecondPage.side_idx + 3 + navs2[code][1]*2) < length ? 'visible' : 'hidden';	// 更多侧边栏菜单项箭头是否显示
		SecondPage.updateSideBg();
	},
	recommendClick: function() {										// 推荐位点击事件
		SecondPage.updateCurrentUri();
		var id = Epg.btn.current.id;
		if(/^djdak_/.test(id)) {
			SecondPage.isOrder({type:'recommend_video', code:Epg.btn.current.code});
		}else if('recommend_big' === id) {
			SecondPage.isOrder({type:groups[0].metadatas[SecondPage.carousel_index].type, code:groups[0].metadatas[SecondPage.carousel_index].value});
		}else if(/^recommend_/.test(id)) {
			SecondPage.isOrder({type:Epg.btn.current.type, code:Epg.btn.current.code});
		}else {
			SecondPage.isOrder({type:'recommend_series', code:Epg.btn.current.code});
		}
	},
	isOrder: function(recommend) {										// 推荐位等的判断事件
		var type = recommend.type, code = recommend.code;
		if('album' === type || 'activity' === type) {
			SecondPage.getActivityOrAlbum(code);
		}else if('recommend_series' === type) {
			Epg.go('column/subSeries/subSeries'+CONFIG.EXT+'?code='+code);
		}else {
			if("free" != SecondPage.orderType) {
				Epg.goMP('column/mp/mp'+CONFIG.EXT+'?method=playVideo&code='+code);
			}else {
				Epg.go('column/order/order'+CONFIG.EXT+'?source='+CONFIG.COLUMN_CODE+'&code='+code);
			}
		}
	},
	getActivityOrAlbum: function(code) {								// 进入活动或者专辑页面
		var postData = {'code':code, 'appVersion':CONFIG.APP_VERSION, 'role':SecondPage.role};
		Epg.postAPI('epg/get', postData, function(data) {
			if(data && data.code === 0) {
				Epg.go(data.epg.path);
			}
		});
	},
	recommendBeforeMove: function(dir, current) {						// 推荐位移动前的判断事件
		if("left" === dir && !(current.left && current.left.length > 0)) {
			SecondPage.recommendPrevButtonId = current.id;
			Epg.btn.set(SecondPage.sidePrevButtonId);
			return false;
		}else if("up" === dir && !(current.up && current.up.length > 0)) {
			SecondPage.recommendPrevButtonId = current.id;
			Epg.btn.set(SecondPage.navPrevButtonId || 'nav_'+navs2[code][0]);
			return false;
		}
	},
	recommendFocusHandler: function() {
		Epg.marquee.start();		
		var id = Epg.btn.current.id;
		Epg.addClass(G(id).parentElement, 'label_recommend_scale');
	},
	recommendBlurHandler: function() {
		Epg.marquee.stop();
		var id = Epg.btn.previous.id;
		Epg.removeClass(G(id).parentElement, 'label_recommend_scale');
	},
	marqueeStart: function() {											// 文本进行滚动
		var id = Epg.btn.current.id + '_txt';
		var marqueeParent = G(id);
		var html = Epg.trim(marqueeParent.innerHTML);
		SecondPage.html = html;
		marqueeParent.innerHTML = '<div id="'+id+'_marquee" class="marquee"><div><div>'+html+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div>'+html+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></div></div>';
		var marqueeChild = G(id+'_marquee').getElementsByTagName('div')[0].getElementsByTagName('div')[0];
		var width1 = parseInt(Epg.css(marqueeParent, 'width'));
		var width2 = parseInt(Epg.css(marqueeChild, 'width'));
		if(width1 < width2) {
			//var offsetWidth = marqueeChild.getElementsByTagName('div')[0].offsetWidth;
			function scroll() {
				animator = new Animator(6000, function(p) {
					if(G(id+'_marquee')) {
						G(id+'_marquee').scrollLeft = p * width2;						
					}
				});
				animator.start(function() {
					G(id+'_marquee').scrollLeft = 0;
					scroll();					
				})				
			}
			scroll();
		}else {
			G(id).innerHTML = '<div id="'+id+'_marquee" class="marquee"><div><div>'+html+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></div></div>';
		}
	},
	marqueeStop: function() {											// 文本滚动停止
		var id = Epg.btn.previous.id + '_txt';
		animator && animator.stop();
		G(id + '_marquee').scrollLeft = 0;
		G(id).innerHTML = SecondPage.html;
	},
	djdakFocusHandler: function(current) {								// 大家都爱看文本获得焦点
		var id = current.id;
		var name = current.videoName;
		if("ggly_iptv_song" === CONFIG.COLUMN_CODE){
			name = current.seriesName;
		}
		G(id+"_txt").innerHTML = name;
		SecondPage.marqueeStart();
	},
	djdakBlurHandler: function(prev) {									// 大家都爱看文本失去焦点
		var id = prev.id;
		SecondPage.marqueeStop();
		var name = prev.seriesName;
		if("ggly_iptv_song" === CONFIG.COLUMN_CODE){
			name = prev.videoName;
		}
		G(id+"_txt").innerHTML = name;
	},
	initDjdak: function(label, f) {										// 初始化大家都爱看列表信息
		document.querySelector('.djdak_title').style.backgroundImage = 'url(images/djdak_title.png)';
		document.querySelector(".djdak").style.backgroundImage = 'url(images/djdak_bg.png)';
		Epg.postAPI("tag/get-videoList-byTagType", {"tagCode":label, "topLimit":5}, function(res) {
			if(res && res.code === 0) {
				var videoList = res.videoList, html = "";
				if("ggly_iptv_song" === CONFIG.COLUMN_CODE){
					for(var i = 0, length = videoList.length; i < length; i++) {
						html += '<div id="djdak_'+i+'"><div id="djdak_'+i+'_txt" class="djdak_txt">'+videoList[i].name+'</div></div>';
						buttons.push({id:'djdak_'+i, code:videoList[i].code, videoName:videoList[i].name,seriesName:videoList[i].intro,action:SecondPage.recommendClick, focusHandler:SecondPage.djdakFocusHandler, blurHandler:SecondPage.djdakBlurHandler, beforeMove:SecondPage.recommendBeforeMove, focusClass:'djdak', autoDirGroup:4});
					}
				}else{
					for(var i = 0, length = videoList.length; i < length; i++) {
						html += '<div id="djdak_'+i+'"><div id="djdak_'+i+'_txt" class="djdak_txt">'+videoList[i].intro+'</div></div>';
						buttons.push({id:'djdak_'+i, code:videoList[i].code, videoName:videoList[i].name,seriesName:videoList[i].intro,action:SecondPage.recommendClick, focusHandler:SecondPage.djdakFocusHandler, blurHandler:SecondPage.djdakBlurHandler, beforeMove:SecondPage.recommendBeforeMove, focusClass:'djdak', autoDirGroup:4});
					}
				}
				G("djdak").innerHTML = html;
			}
			Epg.autoMakeBtnDir(buttons);
			Epg.btn.init([f, 'recommend_big'], buttons, '', false);
		});
	},
	autoPlay: function() {												// 最大推荐位进行轮播
		SecondPage.carousel_index++;
		SecondPage.carousel_index = SecondPage.carousel_index >= 3 ? 0 : SecondPage.carousel_index;
		var span = G("recommend_big").getElementsByTagName('span');
		var li = G("recommend_big").getElementsByTagName('li');
		Array.prototype.slice.call(span).forEach(function(value, index) {
			value.className = index === SecondPage.carousel_index ? 'recommend_big_show' : '';			
		});
		Array.prototype.slice.call(li).forEach(function(value, index) {
			value.className = index === SecondPage.carousel_index ? 'recommend_dian' : '';
		});
	},
	initRecommendBig: function() {										// 初始化大推荐位信息
		var html = "", metadatas = groups[0].metadatas;
		for(var i = 0, length = 3; i < length; i++) {
			html += '<span style="background-image:url('+CONFIG.EPG_PATH+metadatas[i].linkImageUri+')" class='+(i===SecondPage.carousel_index?"recommend_big_show":"")+'></span>';
		}
		/*html += '<div class="recommend_big_txt">'+metadatas[SecondPage.carousel_index].label+'</div>';*/
		html += '<ul>';
		for(i = 0; i < length; i++) {
			html += '<li class='+(i===SecondPage.carousel_index?"recommend_dian":"")+'></li>';
		}
		html += '</ul>';
		G("recommend_big").innerHTML = html;
		recommend_big_interval = setInterval(function() {
			SecondPage.autoPlay();
		}, 4000);
	},
	initRecommend: function() {											// 初始化精选推荐位信息
		var html = "", metadatas = groups[0].metadatas;
		for(var i = 0, length = metadatas.length > 8 ? 5 : (metadatas.length - 3); i < length; i++) {
			html += '<div style="background-image:url('+CONFIG.EPG_PATH+metadatas[(i+3)].linkImageUri+')"><div id="recommend_'+i+'"></div><div id="recommend_'+i+'_txt" class="recommend_txt">'+metadatas[(i+3)].label+'</div></div>';
			buttons.push({id:'recommend_'+i, down:['recommend_down'], type:metadatas[(i+3)].type, code:metadatas[(i+3)].value, focusHandler:SecondPage.recommendFocusHandler, blurHandler:SecondPage.recommendBlurHandler
				, action:SecondPage.recommendClick, beforeMove:SecondPage.recommendBeforeMove, focusClass:'recommend', autoDirGroup:4});
		}
		G("recommends").innerHTML = html;
	},
	initLabelRecommend: function(f) {									// 初始化标签推荐位信息
		recommend_big_interval && clearInterval(recommend_big_interval);
		var id = Epg.btn.current && Epg.btn.current.id;
		SecondPage.initButtons();										// 重新初始化按钮
		var value = groups[1].metadatas[parseInt(SecondPage.sidePrevButtonId.slice(5))-1].value;
        console.log("value:::"+value);
		Epg.postAPI("epg/get", {"code":value, "appVersion":"hd", "role":SecondPage.role}, function(res) {
			if(res && res.code === 0) {
				var label = res.epg.groups[0].metadatas[0].label;
				Epg.postAPI("tag/get-tagList-byType", {"tagType":label, "pageSize":100}, function(res) {
					if(res && res.code === 0 && res.pb.dataList.length) {
						var dataList = res.pb.dataList, html = '<div class="label_recommends">';
						for(var i = 0, length = dataList.length; i < length; i++) {
							html += '<div data-url="'+CONFIG.EPG_PATH+dataList[i].thumbHD+'" data-epg-btn><div id="label_recommend_'+i+'"></div><div id="label_recommend_'+i+'_txt" class="label_recommend_txt">'+dataList[i].name+'</div>';
							if(dataList[i].isNew == 100){
								html += '<div class="tag_new"></div>';
							}
							if(dataList[i].score){
								html += '<div class="tag_score"><div class="score_txt">'+dataList[i].score+'</div></div>';
							}
							html += '</div>';
							var obj = {id:'label_recommend_'+i, code:dataList[i].code, right:i>=(length-1)?[]:'', up:i<5?['recommend_up']:'', down:((Math.ceil((i+1) / 5) * 5)>=length && SecondPage.sidePrevButtonId !== ("side_"+groups[1].metadatas.length))?['recommend_down']:'', 
								action:SecondPage.recommendClick, focusHandler:SecondPage.recommendFocusHandler, blurHandler:SecondPage.recommendBlurHandler, beforeMove:SecondPage.recommendBeforeMove, focusClass:'label_recommend', autoDirGroup:6};
							if(i < 5) {
								obj['restoreScroll'] = true;
							}else {
								obj['scrollScreen'] = true;
							}
							buttons.push(obj);
						}
						html += '</div>';
						G("label_recommends").innerHTML = html;
						Epg.autoMakeBtnDir(buttons);
						if("recommend_up" === id) {
							Epg.btn.init([f, 'label_recommend_'+(parseInt((length-1)/5)*5)], buttons, '', false);	
						}else {
							Epg.btn.init([f, 'label_recommend_0'], buttons, '', false);							
						}
						Epg.scrollScreen.init({wrapperId: 'label_recommends', safePx: 5});
						Epg.scrollScreen.check(Epg.btn.current);
						realFunc();
					}else {
						SecondPage.initLabelRecommendFail();	
					}
				}, function(res) {
					SecondPage.initLabelRecommendFail();
				});
			}
		}, function(res) {
			SecondPage.initLabelRecommendFail();
		});
	},
	initLabelRecommendFail: function() {								// 初始化标签推荐位信息失败处理方法
		var id = Epg.btn.current.id;
		var side = parseInt((SecondPage.sidePrevButtonId).slice(5));
		if("recommend_down" === id) {
			SecondPage.sidePrevButtonId = "side_" + (side - 1);
		}else {			
			SecondPage.sidePrevButtonId = "side_" + (side + 1);			
		}
		// 触发侧边栏菜单项获得焦点事件
		Epg.btn.get(SecondPage.sidePrevButtonId).focusHandler({id:SecondPage.sidePrevButtonId, index:parseInt((SecondPage.sidePrevButtonId).slice(5))});	
		SecondPage.init();		
	},
	navClick: function() {												// 菜单栏点击事件
		SecondPage.updateCurrentUri();
		var code = Epg.btn.current.code;
		if(code === CONFIG.COLUMN_CODE) return;
		if("ggly_iptv_home" === code) {
			location.href = CONFIG.EPG_PATH+'column/iptv_home/iptv_home'+CONFIG.EXT+'?f=nav_0';
		}else if("ggly_iptv_more" === code) {
			location.href = CONFIG.EPG_PATH+'column/morePage/morePage'+CONFIG.EXT;
		}else if("ggly_iptv_area" === code) {
			location.href = CONFIG.EPG_PATH+'column/areaPage/areaPage'+CONFIG.EXT;
		}else if("nav_order" === code) {
			Epg.go('column/order/order'+CONFIG.EXT);
		}else if("nav_search" === code) {
			Epg.go('column/search/search'+CONFIG.EXT);
		}else if("nav_history" === code) {
			Epg.go('column/history/history'+CONFIG.EXT+'?isPlay=true');
		}else if("nav_fav" === code) {
			Epg.go('column/fav/seriesFav'+CONFIG.EXT+'?isPlay=true');
		}else {
			location.href = CONFIG.EPG_PATH+'column/secondPage/secondPage'+CONFIG.EXT+'?code='+code;			
		}
	},
	navBeforeMove: function(dir, current) {								// 菜单栏移动前的判断事件
		if("down" === dir) {
			SecondPage.navPrevButtonId = current.id;
			if(SecondPage.recommendPrevButtonId !== "") {
				Epg.btn.set(SecondPage.recommendPrevButtonId);
			}else if(Epg.btn.get("label_recommend_0")) {
				Epg.btn.set("label_recommend_0");
			}else {
				Epg.btn.set("recommend_big");	
			}			
			return false;
		}
	},
	recommendUpOrDownFocusHandler: function() {							// 推荐位上下翻页箭头获得焦点事件
		var id = Epg.btn.current.id;
		var side = parseInt((SecondPage.sidePrevButtonId).slice(5));
		if("recommend_down" === id) {
			SecondPage.sidePrevButtonId = "side_" + (side + 1);
		}else {			
			SecondPage.sidePrevButtonId = "side_" + (side - 1);			
		}
		// 触发侧边栏菜单项获得焦点事件
		Epg.btn.get(SecondPage.sidePrevButtonId).focusHandler({id:SecondPage.sidePrevButtonId, index:parseInt((SecondPage.sidePrevButtonId).slice(5))});
		SecondPage.init();
	},
	initButtons: function() {											// 初始化光标按钮事件
		buttons = [
			{id:'nav_order', code:'nav_order', left:['nav_7'], action:SecondPage.navClick, beforeMove:SecondPage.navBeforeMove, focusClass:'nav_order', autoDirGroup:1},
			{id:'nav_search', code:'nav_search', action:SecondPage.navClick, beforeMove:SecondPage.navBeforeMove, focusClass:'nav_search', autoDirGroup:1},
			{id:'nav_history', code:'nav_history', action:SecondPage.navClick, beforeMove:SecondPage.navBeforeMove, focusClass:'nav_history', autoDirGroup:1},
			{id:'nav_fav', code:'nav_fav', action:SecondPage.navClick, beforeMove:SecondPage.navBeforeMove, focusClass:'nav_fav', autoDirGroup:1},
			{id:'recommend_big', action:SecondPage.recommendClick, beforeMove:SecondPage.recommendBeforeMove, focusClass:'recommend_big', autoDirGroup:4},
			{id:'recommend_up', focusHandler:SecondPage.recommendUpOrDownFocusHandler, autoDirGroup:false},
			{id:'recommend_down', focusHandler:SecondPage.recommendUpOrDownFocusHandler, autoDirGroup:false}
		];
		for(var i = 0, length = navs.length; i < length; i++) {
			buttons.push({id:'nav_'+i, code:navs[i], right: i===7?['nav_order']:'', action:SecondPage.navClick, beforeMove:SecondPage.navBeforeMove, focusClass:'nav', autoDirGroup:2});
		}		
		buttons.push({id:'side_0', index:0, action:SecondPage.sideClick, beforeMove:SecondPage.sideBeforeMove, focusHandler:SecondPage.sideFocusHandler, focusClass:'side', autoDirGroup:3});
		for(var i = 0, length = groups[1].metadatas.length; i < length; i++) {
			buttons.push({id:'side_'+(i+1), index:(i+1), value:groups[1].metadatas[i].value, action:SecondPage.sideClick, beforeMove:SecondPage.sideBeforeMove, focusHandler:SecondPage.sideFocusHandler, focusClass:'side', autoDirGroup:3});
		}
	},
	init: function(f) {													// 初始化推荐位信息
        //G("recommend_big").style.display = "side_0" === SecondPage.sidePrevButtonId ? "block" : "none";
        //document.querySelector(".djdak_title").style.display = "side_0" === SecondPage.sidePrevButtonId ? "block" : "none";
        //document.querySelector(".djdak").style.display = "side_0" === SecondPage.sidePrevButtonId ? "block" : "none";
        //G("recommends").style.display = "side_0" === SecondPage.sidePrevButtonId ? "block" : "none";
        //console.log("SecondPage.sidePrevButtonId:::"+SecondPage.sidePrevButtonId);
		if("side_0" === SecondPage.sidePrevButtonId) {
			var id = Epg.btn.current && Epg.btn.current.id;
			var prevId = Epg.btn.previous && Epg.btn.previous.id;
			if('recommend_up' === id) {
				SecondPage.initSide('true', 'recommend_'+parseInt(prevId.slice(16)));
			}else {
				SecondPage.initSide("true", f || '');					// 初始化侧边栏
			}
			H("label_recommends");										// 隐藏标签推荐位
			SecondPage.initRecommendBig();								// 初始化大推荐位
			SecondPage.initRecommend();									// 初始化精选推荐位
		}else {
			SecondPage.initSide("false", f || '');						// 初始化侧边栏
			S("label_recommends");										// 显示标签推荐位
			SecondPage.initLabelRecommend(f || '');						// 初始化标签推荐位
		}
	},
	updateCurrentUri: function() {
		CONFIG.CURRENT_URI = uri + '&side_idx='+SecondPage.side_idx+'&sidePrevButtonId='+SecondPage.sidePrevButtonId+'&navPrevButtonId='+SecondPage.navPrevButtonId+
			'&recommendPrevButtonId='+SecondPage.recommendPrevButtonId+'&carousel_index='+SecondPage.carousel_index;
	}
};

var buttons = [];
var animator;
var navs = ['ggly_iptv_home', 'ggly_iptv_animation', 'ggly_iptv_early', 'ggly_iptv_song', 'ggly_iptv_story', 'ggly_iptv_puzzle', 'ggly_iptv_area', 'ggly_iptv_more'];
var navs2 = {'ggly_iptv_animation':[1,1], 'ggly_iptv_early':[2,1], 'ggly_iptv_song':[3,0], 'ggly_iptv_story':[4,0], 'ggly_iptv_puzzle':[5,0]};
var groups = [], recommend_big_interval;	// recommend_big_interval --清理定时器

function back() {	
	//location.href = Epg.getBackURI();
	location.href = CONFIG.EPG_PATH+'column/iptv_home/iptv_home'+CONFIG.EXT+'?f=nav_'+navs2[code][0]+'&source='+CONFIG.COLUMN_CODE;
}

// 简单的节流函数
function throttle(func, wait, mustRun) {
    var timeout,  startTime = new Date();
    return function() {
        var context = this, args = arguments, curTime = new Date();
        clearTimeout(timeout);
        // 如果达到了规定的触发时间间隔，触发 handler
        if(curTime - startTime >= mustRun){
            //func.apply(context,args);
            func();
            startTime = curTime;
        // 没达到触发间隔，重新设定定时器
        }else{
            timeout = setTimeout(func, wait);
        }
    };
};
// 实际想绑定在 scroll 事件上的 handler
function realFunc(wrapperId){
	wrapperId = wrapperId || Epg.scrollScreen.config.wrapperId;
	var iScrollTop = G(wrapperId).scrollTop;
	var iClientTop = G(wrapperId).getBoundingClientRect().top + iScrollTop;
	var iClientBottom = G(wrapperId).offsetHeight + iClientTop;
	var btns = document.querySelectorAll("[data-epg-btn]");
	for(var i = 0; i < btns.length; i++) {		
		var obj = btns[i];
		// 加载过了的就不需要加载了
		if(!Epg.hasClass(obj, "loaded")) {
			var iTop = Epg.getAbsolutePosition(obj).top;
			var iBottom = iTop + obj.offsetHeight;
			if((iTop > iClientTop && iTop < iClientBottom) || (iBottom > iClientTop && iBottom < iClientBottom)) {
				obj.style.backgroundImage = 'url('+obj.getAttribute("data-url")+')';
				Epg.addClass(obj, "loaded");				
			}			
		}
	}
}

window.onunload = function() {
	recommend_big_interval && clearInterval(recommend_big_interval);
	animator && animator.stop();
};

;(function() {
	G("nav_bg").style.left = navs2[code][0] * 102 + "px";
	Epg.addClass(G("side_bg"), code);
	if(!navs2[code][1]) {
		G("sides").style.height = "184px";
		G("side_more").style.top = "275px";
	}
	Epg.key.init();
	Epg.key.set({
		KEY_ENTER: 'Epg.Button.click()',			//确定键
		KEY_LEFT: 'Epg.Button.move("left")',		//左键
		KEY_RIGHT: 'Epg.Button.move("right")',		//右键
		KEY_UP: 'Epg.Button.move("up")',			//上键
		KEY_DOWN: 'Epg.Button.move("down")',		//下键
		KEY_BACK: back								//返回键
	});	
	Epg.postAPI("epg/get", {"code":code, "appVersion":"hd", "role":SecondPage.role}, function(res) {
		if(res && res.code === 0) {
			groups = res.epg.groups;
			SecondPage.init(Epg.getParam('f'));		
		}
	});	
	G("label_recommends").addEventListener('scroll', throttle(realFunc, 250, 500));
})();
